import {defineStore} from "pinia";
import {ref} from "vue";
import {User} from "../interfaces/User.js"
import {searchUser} from "../apis/UserApi.js";
import {Result} from "../interfaces/Result.ts";
import {elPrompt} from "../utils/elPrompt.ts";

export const useUserStore = defineStore('user', () => {
    const value = ref<User>()
    async function loadUserData() {
        await searchUser((result: Result<User>) => {
            if (result.status !== 200) return elPrompt(result.message, "error")
            value.value = result.data
        })
    }
    async function getValue():Promise<User | undefined>  {
        await loadUserData()
        return value.value
    }

    return { getValue }
})